package com.ict.web.dto;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.ict.common.core.domain.entity.SysUser;
import com.ict.common.utils.DateUtils;
import com.ict.common.utils.bean.BeanUtils;
import com.ict.common.utils.uuid.IdUtils;
import com.ict.web.controller.file.domain.YzqFile;
import com.ict.web.controller.file.dto.YzqFileDTO;
import com.ict.web.domain.ExpertInformationSheet;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Data
public class InsertExpertInformationSheetDto {

    @ApiModelProperty(value = "专家姓名")
    private String expertName;

    @ApiModelProperty(value = "性别{0：男 1：女}")
    private String sex;

    @ApiModelProperty(value = "政治面貌")
    private String politicalOutlook;

    @ApiModelProperty(value = "身份证号码")
    private String idNumber;

    @ApiModelProperty(value = "手机号码")
    private String phoneNumber;

    @ApiModelProperty(value = "电子邮箱")
    private String email;

    @ApiModelProperty(value = "联系地址")
    private String contactAddress;

    @ApiModelProperty(value = "毕业学院")
    private String graduateCollege;

    @ApiModelProperty(value = "专业")
    private String major;

    @ApiModelProperty(value = "学历")
    private String education;

    @ApiModelProperty(value = "毕业时间")
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8", shape = JsonFormat.Shape.STRING)
    private Date graduationTime;

    @ApiModelProperty(value = "工作单位")
    private String workUnit;

    @ApiModelProperty(value = "职务")
    private String post;

    @ApiModelProperty(value = "擅长领域")
    private String areasOfExpertise;

    @ApiModelProperty(value = "工作年限")
    private String workingYears;

    //以下都是文件类型
    @ApiModelProperty(value = "最高学历证书")
    private YzqFileDTO haCertificateFile;

    @ApiModelProperty(value = "工作单位意见")
    private YzqFileDTO workUnitOpinionsFile;

    @ApiModelProperty(value = "身份证")
    private YzqFileDTO idCardFile;

    @ApiModelProperty(value = "个人照片")
    private YzqFileDTO personalPhotosFile;

    @ApiModelProperty(value = "年龄")
    private Integer age;

    @ApiModelProperty(value = "职业资格表")
    private List<InsertProfessionalQualificationDto> qualificationAddDtoS;

    @ApiModelProperty(value = "技术职称")
    private List<InsertTechnicalTitleDto> technicalTitleDtoS;

    public static ExpertInformationSheet of(InsertExpertInformationSheetDto dto) {
        ExpertInformationSheet bean = new ExpertInformationSheet();
        BeanUtils.copyProperties(dto, bean);
        //设置ID
        bean.setExpertId(IdUtils.snowId());
        //设置创建时间
        bean.setCreateTime(DateUtils.getNowDate());
        //设置创建时间
        bean.setUpdateTime(DateUtils.getNowDate());
        //设置删除标记
        bean.setDelFlag(ExpertInformationSheet.DELETE_STATUS_NORMAL);

        return bean;
    }


    /**
     * 将 InsertExpertInformationSheetDto中需传文件对象 转化为 file
     *
     * @param dto 接收dto
     * @return HotelInfo
     */
    public static ArrayList<YzqFile> toFile(ExpertInformationSheet expertInformationSheet, InsertExpertInformationSheetDto dto) {
        ArrayList<YzqFile> fileList = new ArrayList<>();
        if (dto.getHaCertificateFile() != null) {
            YzqFileDTO Hc = dto.getHaCertificateFile();
            YzqFile fileHc = new YzqFile();
            fileHc.setId(String.valueOf(IdUtils.snowId()));
            BeanUtils.copyProperties(Hc, fileHc);
            fileList.add(fileHc);
            expertInformationSheet.setHaCertificateFile(fileHc.getId());
        }

        if (dto.getWorkUnitOpinionsFile() != null) {
            YzqFileDTO Wo = dto.getWorkUnitOpinionsFile();
            YzqFile fileWo = new YzqFile();
            fileWo.setId(String.valueOf(IdUtils.snowId()));
            BeanUtils.copyProperties(Wo, fileWo);
            fileList.add(fileWo);
            expertInformationSheet.setWorkUnitOpinionsFile(fileWo.getId());
        }

        if (dto.getIdCardFile() != null) {
            YzqFileDTO Ic = dto.getIdCardFile();
            YzqFile fileIc = new YzqFile();
            fileIc.setId(String.valueOf(IdUtils.snowId()));
            BeanUtils.copyProperties(Ic, fileIc);
            fileList.add(fileIc);
            expertInformationSheet.setIdCardFile(fileIc.getId());
        }

        if (dto.getPersonalPhotosFile() != null) {
            YzqFileDTO Pp = dto.getPersonalPhotosFile();
            YzqFile filePp = new YzqFile();
            filePp.setId(String.valueOf(IdUtils.snowId()));
            BeanUtils.copyProperties(Pp, filePp);
            fileList.add(filePp);
            expertInformationSheet.setPersonalPhotosFile(filePp.getId());
        }

        return fileList;
    }
}
